package com.oo.app.ui.main.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import com.oo.app.ui.main.activity.HtmlActivity;

import java.util.List;

/**
 * @创建者 喻亚龙
 * @描述
 */

public class GuidePagerAdapter extends PagerAdapter {
    private Context context;
    private List<View> viewList;

    public GuidePagerAdapter(Context context, List<View> viewList) {
        this.context = context;
        this.viewList = viewList;
    }

    /**
     * 返回页面的个数
     *
     * @return
     */
    @Override
    public int getCount() {
        if (viewList != null) {
            return viewList.size();
        }
        return 0;
    }

    /**
     * 判断是否由对象生成界面
     *
     * @param view
     * @param object
     * @return
     */
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    /**
     * 初始化position位置的界面
     *
     * @param container
     * @param position
     * @return
     */
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ((ViewPager) container).addView(viewList.get(position), 0);
        viewList.get(position).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {//跳h5广告
//                HtmlActivity.show(context);
            }
        });
        return viewList.get(position);
    }

    /**
     * 移除页面
     *
     * @param container
     * @param position
     * @param object
     */
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager) container).removeView(viewList.get(position));
    }
}
